USE Lib
GO

---------------------------------------------------------------------------
-- BEGIN MAINTENANCE WRAPPER
----------------------------
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'fn_isnull_or_empty') BEGIN
	DROP  FUNCTION  tsql.fn_isnull_or_empty
	PRINT '<<< DROP FUNCTION tsql.fn_isnull_or_empty - Completed with SUCCESS >>>'
END

GO
----------------------------
-- END MAINTENANCE WRAPPER
---------------------------------------------------------------------------

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*================================================================================================
Name:			tsql.fn_isnull_or_empty
Type:			User defined function 
Owner:			
Description:	Determines if a value is null or empty 
Parameters:		@value = value to be evaluated
Dependens on:  	none
Usage:			SELECT tsql.fn_fn_isnull_or_empty(null)
--------------------------------------------------------------------------------------------------
Project:		http://sqllib.codeplex.com/
Help:			http://sqllib.codeplex.com/wikipage?title=fn_isnull_or_empty&referringTitle=Documentation		
Version:		20120822
SrcCtrlApp:		SVN
SrcCtrlPath:	http://sqllib.codeplex.com/SourceControl/list/changesets
--------------------------------------------------------------------------------------------------
History:		07/20/2012 - Adrian E Dudau - Function created
History:		08/22/2012 - Adrian E Dudau - Added references to project, SVN and Help
================================================================================================*/

CREATE FUNCTION [tsql].[fn_isnull_or_empty] (@value sql_variant)
RETURNS BIT AS
BEGIN


	IF @value IS NULL OR LEN(CAST(@value AS VARCHAR) + '') = 0   
		RETURN 1

	-- ELSE
	RETURN 0		
END /*FUNCTION*/

GO

---------------------------------------------------------------------------
-- BEGIN MAINTENANCE WRAPPER
-- Verify completion
----------------------------

IF EXISTS(SELECT * FROM sysobjects WHERE name = 'fn_isnull_or_empty') BEGIN 
	PRINT '<<< CREATE FUNCTION tsql.fn_isnull_or_empty - Completed with SUCCESS >>>'
END

ELSE BEGIN 
	PRINT '<<< CREATE FUNCTION tsql.fn_isnull_or_empty - Completed with ERROR >>>'
END


GO
----------------------------
-- END MAINTENANCE WRAPPER
---------------------------------------------------------------------------

-- GRANT SELECT TO PUBLIC will be used at Db level



